define(['text!./relation.html', 'css!./relation.css'], function(html) {
	avalon.templateCache['relation'] = html;
	var vm = avalon.define({
		$id: "relation",
		role: '',
		emPhone: '',
		iduNum:"",
		device: function() {
			var family=JSON.parse(getstorage('family'));
			family={
				name:family.name,
				realName:family.realName,
				sex:family.sex,
				phone:family.phone,
				tel:family.tel,
				emPhone:vm.emPhone,
				height:family.height,
				weight:family.weight,
				date:family.date
			}
			var user=JSON.parse(getstorage('user'));
//			alert(vm.role);
			if(vm.role=='self'){
				var type=0;
				var password=user.password;
				var user_id=user.user_id;
				var refreshToken=user.refreshToken;
				var unionid=user.unionid;
				var deviceId=user.deviceId;
				var deviceinfo=user.deviceinfo;
				var headphoto=user.headphoto;
			}else{
				var type=1;
				var password=null;
				var user_id=null;
				var refreshToken=null;
				var unionid=null;
				var deviceId=null;
				var deviceinfo=null;
				var headphoto=null;
			}
			httpPost('user/updateUser', {
				type: type,
				userId: user.idu,//用户id
				name: family.name,
				realName:family.realName,
				password:password,
				birthday:family.date, //生日
				sex: family.sex, //性别 1：男，0：女
				phone: family.phone, //手机号码
				tel: family.tel, //座机号码
				emPhone: vm.emPhone, //紧急联系电话
				user_id: user_id, //所属家人id
				refreshToken: refreshToken,
				height: family.height, //身高
				weight: family.weight, //体重
				unionid: unionid,
				deviceId: deviceId, //移动设备id
				deviceinfo: deviceinfo, //1：iOS，0：Android
				status: "1", //0：删除，1：有效
				headphoto: headphoto //头像base64编码
			}).done(function(data) {
				if("200" == data.code) {
					if(vm.role=="self"){
						clearstorage('family');
						setstorage('user',data.user);
						setstorage('idunum',data.user.idu);
						msgbox('提示','保存成功,是否立即测量','bindNum()',1,'cancel()');
					}else{
						clearstorage('family');
						setstorage('idunum',data.user.idu);
						msgbox('提示','保存成功,是否立即测量','bindNum()',1,'cancel()');
					}
				} else {
					msgbox('提示',data.msg);
				}
			});
		},
		back: function() {
			if(vm.role != 'self') {
				Router.go('/detailInfo/detailInfo');
			} else {
				Router.go('/detailSelf/detailSelf');
			}

		},
		contentList: function() {
			vm.role = Router.contentList;
		},
		init: function() {
			vm.contentList();
		}
	});
});
function cancel(){
	Router.go('/Home/Home');
	clearstorage('idunum');
}
function bindNum(){
	var id=JSON.parse(getstorage('idunum'));
	scanCode(1,id);
	clearstorage('idunum');
}
